package com.funny.rabbitmq.pubsub.topic;

import com.funny.rabbitmq.utils.RabbitMQUtils;
import com.rabbitmq.client.Channel;
import com.rabbitmq.client.MessageProperties;

import java.util.HashMap;
import java.util.Map;

public class Producer {

    private final static String EXCHANGE_NAME = "logs.topic";
    private final static String QUEUE_NAME = "console";
    private final static String ROUTING_KEY = "funnywus.";


    public static void main(String[] args) throws Exception {
        Channel channel = RabbitMQUtils.getChannel();
        // 声明交换机
//        channel.exchangeDeclare(EXCHANGE_NAME, BuiltinExchangeType.FANOUT, true);
        // 声明队列
//        channel.queueDeclare(QUEUE_NAME, true, false, false, null);
        // 将路由键与队列、交换机绑定
//        channel.queueBind(QUEUE_NAME, EXCHANGE_NAME, ROUTING_KEY);

        Map<String, String> bindingKeyMap = new HashMap<>();
        bindingKeyMap.put("funnywus.a", "Q1");
        bindingKeyMap.put("a.funnywus.a", "Q1, Q2");
        bindingKeyMap.put("a.a.funnywus.a.a", "Q1, Q2");

        for (Map.Entry<String, String> entry : bindingKeyMap.entrySet()) {
            String routingKey = entry.getKey();
            String msg = entry.getValue();
            channel.basicPublish(EXCHANGE_NAME, routingKey, MessageProperties.PERSISTENT_TEXT_PLAIN, msg.getBytes());
        }

       /* Scanner scanner = new Scanner(System.in);
        while (scanner.hasNext()) {
            int i = scanner.nextInt();
            String msg = "hello world_" + i;
            channel.basicPublish(EXCHANGE_NAME, ROUTING_KEY, MessageProperties.PERSISTENT_TEXT_PLAIN, msg.getBytes());
            System.out.println("消息发送成功");
        }*/
    }
}
